package com.hospital.service.impl;

import com.hospital.dao.DepartInfoDao;
import com.hospital.entity.DepartInfo;
import com.hospital.service.intf.DepartInfoService;
import com.hospital.util.StringUtil;
import com.hospital.vo.PageBean;
import com.hospital.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author fxy
 * @date 2022/8/29
 */
@Service
public class DepartInfoServiceImpl implements DepartInfoService {
    @Autowired
    private DepartInfoDao departInfoDao;
    @Override
    public R add(DepartInfo departInfo) {
        if(departInfoDao.add(departInfo)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(Integer id) {
        if(departInfoDao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(DepartInfo departInfo) {
        if(departInfoDao.update(departInfo)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String name, int start, int limit) {
        if(StringUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }
        int start1=(start-1)*limit;
        return PageBean.ok(departInfoDao.selectCount(name),departInfoDao.selectPage(name,start1,limit));

    }

    @Override
    public R query() {
        return R.ok(departInfoDao.query());
    }
}
